package com.qianclass.talklive.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.qianclass.talklive.R;
import com.qianclass.talklive.app.bean.RoomsBean;
import com.qianclass.talklive.app.utils.LogUtil;

import java.util.List;

/**
 * Created by admin on 2017/3/8.
 * <p>
 * 更新时间 2017/3/8
 * 更新描述 ${TODO}
 */

public class CourseAdapter extends BaseAdapter{
    Context         context;
    List<RoomsBean> mList;
    LayoutInflater  mInflater;

    public CourseAdapter(Context context, List<RoomsBean>mList) {
        this.context=context;
        this.mList=mList;
        mInflater=LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mList!=null ? mList.size() : 0;
    }

    @Override
    public Object getItem(int i) {
        return mList!=null ? mList.get(i) : 0;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(final int i, View converView, ViewGroup viewGroup) {

        ViewHolder viewHolder;
        View view;
        if(converView==null){
            //view = mInflater.inflate(R.layout.xlistview_course_item, viewGroup, false);
            view = mInflater.inflate(R.layout.item_course_content, viewGroup, false);
            viewHolder =new ViewHolder(view);
            //viewHolder.mTv_title= (TextView) view.findViewById(R.id.tv_coursename);
            //viewHolder.mTv_time= (TextView) view.findViewById(R.id.tv_starttime);
            //viewHolder.mTv_name= (TextView) view.findViewById(R.id.tv_teachername);
            view.setTag(viewHolder);
        }else{
            view=converView;
            viewHolder= (ViewHolder) view.getTag();
        }

        viewHolder.mTv_title.setText(mList.get(i).getRoomTitle());
        viewHolder.mTv_time.setText(mList.get(i).getStartDateTime());
        viewHolder.mTv_name.setText(mList.get(i).getTeacherName());
        viewHolder.mBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mOnTestClick != null) {
                    mOnTestClick.OnClick(i);
                    LogUtil.i("MVP", "按钮 " + i);
                }
            }
        });

        return  view;
    }

    class ViewHolder {


        TextView mTv_title;
        TextView mTv_time;
        TextView mTv_name;
        Button mBtn;

        public ViewHolder(View root){
            mTv_title= (TextView) root.findViewById(R.id.tv_course_name);
            mTv_time= (TextView) root.findViewById(R.id.tv_course_time);
            mTv_name= (TextView) root.findViewById(R.id.tv_course_teacher);
            mBtn = (Button) root.findViewById(R.id.but_enter_course);
        }
    }
    private OnTestClick mOnTestClick;
    public void setOnClick(OnTestClick onTestClick){
        mOnTestClick=onTestClick;
    }
    public  interface OnTestClick {
        void OnClick(int i);
    }
}
